<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<style>
.input2 {
	border: 1px solid #C8C8C8;
	padding: 3px 5px;
}
.wrc {width:300px;}
.order-border
{
	border: 1px solid #ccc;
	background: #ffffff;
	width: 65%;
	padding: 20px 10px;
}
.error_border
{
	border: 1px solid #ff0000;
}
</style>
<div class="page-content middle padtop10">
	<!-- bread crumb -->
	<p id="bread-crumb">
		<a href="<?php echo site_url('recharge');?>">
			<?php echo $lang['request_recharge'];?>
        </a>
	</p>
	<!-- end bread crumb -->
	<br />
	<h3>
		<?php echo $lang['request_recharge'];?>
	</h3>
	<div class="payment-total-info myclear">
	<br>
		<div class="order-border" style="margin:0 auto">
			<?php if($msg != ''){?>
			<div class="msg"><?php echo base64_decode($msg);?></div><br />
			<?php }?>
			<form name="frmRecharge" action="<?php echo site_url('recharge/createSave');?>" method="post" onsubmit="return checkRecharge();">
				<table width="100%" style="border-spacing:5px">
					<tr>
						<td>
							<b><?php echo $lang['recieve_account'];?></b>
						</td>
						<td>
							<select name="txtTypeUser" class="select" onchange="typeUserChange();" style="width:140px">
								<option value="-1">
									<?php echo $lang['select_type_user'];?>
								</option>
								<option value="0">
									<?php echo $lang['user_real'];?>
								</option>
								<option value="1">
									<?php echo $lang['acc_agency'];?>
								</option>
							</select>
							<select name="txtForGroup" class="select" style="width:150px; display:none">
								<option value="0">
									<?php echo $lang['select'];?>
								</option>
								<?php foreach ($groups as $item){?>
								<option value="<?php echo $item->groupid;?>">
									<?php echo $item->groupname;?>
								</option>
								<?php }?>
							</select>
							<input type="text" class="input2" name="txtForUser" style="width:150px; display:none;padding:2px 3px" />
						</td>
					</tr>
					<tr>
						<td width="150">
							<b><?php echo $lang['amount'];?></b>
						</td>
						<td>
							<input class="input2 wrc" type="text" name="txtAmount" />
						</td>
					</tr>
					<tr>
						<td width="150">
							<b><?php echo $lang['system'];?></b>
						</td>
						<td>
							<select name="txtSystem" class="select">
								<option value="1" selected="selected">CPC</option>
								<option value="2">CPM</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>
							<?php echo $lang['content'];?>
						</td>
						<td>
							<textarea class="input2 wrc" style="height:50px" name="txtDescription"></textarea>
						</td>
					</tr>
					<tr>
						<td style="vertical-align:middle">
							<b><?php echo $lang['style_recharge'];?></b>
						</td>
						<td>
							<select name="txtTypePay" class="select">
								<option value="0">
									<?php echo $lang['select'];?>
								</option>
								<option value="1">
									<?php echo $lang['add_money'];?>
								</option>
								<option value="2">
									<?php echo $lang['transfer_money'];?>
								</option>
							</select>
						</td>
					</tr>
					<tr>
						<td>
							<b><?php echo $lang['receipts'];?></b>
						</td>
						<td>
							<input class="input2 wrc" type="text" name="txtReceipts" />
						</td>
					</tr>
					<tr>
						<td>
							<b><?php echo $lang['comment'];?></b>
						</td>
						<td>
							<textarea class="input2 wrc" style="height:80px" name="txtDes"></textarea>
						</td>
					</tr>
					<tr>
						<td>&nbsp;</td>
						<td class="text-right">
							<br /><br /><br />
							<input class="input2" type="submit" value="<?php echo $lang['send'];?>" />
							<input class="input2" type="button" value="<?php echo $lang['cancel'];?>" onclick="window.location = '<?php echo site_url('recharge');?>';" />
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</div><br>
<script type="text/javascript">
$(document).ready(function(){
	$('input[name="txtAmount"]').setMask({mask : '999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999', type : 'reverse', defaultValue: '0'});

	$('input[name="txtAmount"]').blur(function(){
		frmRecharge.checkAmount();
	});
	$('input[name="txtReceipts"]').blur(function(){
		frmRecharge.checkReceipt();
	});
	$('select[name="txtTypeUser"]').blur(function(){
		frmRecharge.checkTypeUser();
	});
	$('select[name="txtForGroup"]').blur(function(){
		frmRecharge.checkForGroup();
	});
	$('input[name="txtForUser"]').blur(function(){
		frmRecharge.checkForUser();
		$obj = $(this);
		if($obj.val() != '')
		{
			$.ajax({
				url: '<?php echo site_url('recharge/ajaxCheckUsername');?>/?uname='+$obj.val(),
				success: function(data){
					if(data != '1')
					{
						$obj.addClass('error_border');
					}
					else
					{
						$obj.removeClass('error_border');
					}
				}
			});
		}
	});
	$('select[name="txtTypePay"]').blur(function(){
		frmRecharge.checkTypePay();
	});
	$('textarea[name="txtDescription"]').blur(function(){
		frmRecharge.checkContent();
	});
});
var frmRecharge = {
	_check: true,
	checkAmount: function(){
		$obj = $('input[name="txtAmount"]');
		$val = $obj.val();
		$val = $val.replace(/,/g, '');
		if($val == '' || !isIntNumber($val))
		{
			$obj.addClass('error_border').focus();
			this._check = false;
		}
		else $obj.removeClass('error_border');
	},
	checkReceipt: function (){
		$obj = $('input[name="txtReceipts"]');
		if($obj.val() == '')
		{
			$obj.addClass('error_border').focus();
			this._check = false;
		}
		else $obj.removeClass('error_border');
	},
	checkTypeUser: function(){
		$obj = $('select[name="txtTypeUser"]');
		if($obj !== undefined && $obj.val() == '-1')
		{
			$obj.addClass('error_border').focus();
			this._check = false;
		}
		else $obj.removeClass('error_border');
	},
	checkForGroup: function(){
		$obj = $('select[name="txtForGroup"]');
		if($obj !== undefined && $obj.val() == '0' && $obj.css('display') != 'none')
		{
			$obj.addClass('error_border').focus();
			this._check = false;
		}
		else $obj.removeClass('error_border');
	},
	checkForUser: function(){
		$obj = $('input[name="txtForUser"]');
		if($obj !== undefined && $obj.val() == '' && $obj.css('display') != 'none')
		{
			$obj.addClass('error_border').focus();
			this._check = false;
		}
		else $obj.removeClass('error_border');
	},
	checkTypePay: function(){
		$obj = $('select[name="txtTypePay"]');
		if($obj.val() == '0')
		{
			$obj.addClass('error_border').focus();
			this._check = false;
		}
		else $obj.removeClass('error_border');
	},
	checkContent: function(){
		$obj = $('textarea[name="txtDescription"]');
		if($obj.val() == '')
		{
			$obj.addClass('error_border').focus();
			this._check = false;
		}
		else $obj.removeClass('error_border');
	},
	process: function(){
		this._check = true;
		this.checkAmount();
		this.checkTypeUser();
		this.checkForGroup();
		this.checkForUser();
		this.checkTypePay();
		this.checkContent();
		this.checkReceipt();
		return this._check;
	}
};
function checkRecharge()
{
	return frmRecharge.process();
}
function typeUserChange()
{
	$type = $('select[name="txtTypeUser"]');
	if($type.val() == '0')	//theo user
	{
		$('select[name="txtForGroup"]').hide();
		$('input[name="txtForUser"]').show();
	}
	else if($type.val() == '1')	//theo daily
	{
		$('input[name="txtForUser"]').hide();
		$('select[name="txtForGroup"]').show();
	}
	else
	{
		$('input[name="txtForUser"]').hide();
		$('select[name="txtForGroup"]').hide();
	}
}
</script>